#!/bin/bash
#判断跳板机上是否存在某工程版本

error_exit(){
	echo "ERROR: 判断跳板机上是否存在某工程版本失败,$1,jumpServerIp=${jumpServerIp},editionPath=${editionPath}" >> ${logFile}
	echo "ERROR: 判断跳板机上是否存在某工程版本失败,$1,jumpServerIp=${jumpServerIp},editionPath=${editionPath}"
	exit 1
}


jumpServerIp=$1
editionPath=$2
ssh_login_user=$3
ssh_key_file=$4
ssh_port=$5
logFile=$6
shellPath=$7

parentIp=$8
parentPort=$9

loginUser=`whoami`
ssh_key_file=/home/${loginUser}/${ssh_key_file}

echo "判断跳板机上是否存在某工程版本开始,jumpServerIp=${jumpServerIp},editionPath=${editionPath}" >> ${logFile}

#校验远程终端是否可以免密登录
expect ${shellPath}/shell/init/beetle_validate_ssh.sh ${parentIp} ${ssh_login_user} ${ssh_login_user} ${parentPort} > /dev/null || error_exit "校验ssh免密登录失败,host=${parentIp}"

ssh ${loginUser}@${parentIp} -p ${parentPort} -i ${ssh_key_file} "expect /home/${loginUser}/shell/beetle_validate_ssh.sh ${jumpServerIp} ${loginUser} ${loginUser} ${ssh_port} > /dev/null " >> ${logFile} || error_exit "校验二级跳板机ssh免密登录失败,host=${jumpServerIp}"

ssh ${loginUser}@${parentIp} -p ${parentPort} -i ${ssh_key_file} "ssh ${ssh_login_user}@${jumpServerIp} -p ${ssh_port} -i ${ssh_key_file} \"ls ${editionPath}\" " || error_exit

echo "判断跳板机上是否存在某工程版本结束,jumpServerIp=${jumpServerIp},editionPath=${editionPath}" >> ${logFile}